package com.jt.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

public class RedisAOP2 {
	//配置切入点(只对当前类生效)
	@Pointcut("bean(itemCatServiceImpl)")
	public void pointCut() {}

	//前置通知
	@Before("pointCut()")
	public void before() {
		System.out.println("我是前置通知");
	}

	//后置通知
	@AfterReturning("pointCut()")
	public void afterReturning() {
		System.out.println("我是后置通知");
	}

	//异常通知
	@AfterThrowing(pointcut = "pointCut()",throwing = "throwable")
	public void afterThrowing(Throwable throwable) {
		System.out.println(throwable.getMessage());
		System.out.println("我是异常通知");
	}

	//最终通知
	@After("pointCut()")
	public void after() {
		System.out.println("我是最终通知");
	}
	
	//环绕通知
	@Around("pointCut()")
	public Object around(ProceedingJoinPoint joinPonit) throws Throwable {
		try {
			System.out.println("我是环绕通知一");
			Object obj = joinPonit.proceed();
			System.out.println("我是环绕通知二");
			return obj;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
		
	}
}
